home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / VideoToolbox 96.06.15 / VideoToolboxSources / GetVersionString.c < prev    next >
Text File  |  1995-07-26  |  2KB  |  45 lines

  1. /*
  2. GetVersionString.c
  3. Gets the version of a program from the "Short version string" field of
  4. its 'vers' resource. The version is returned as a C string allocated by
  5. NewPtr(). Returns "" if there is no 'vers' 1 resource. Use this to display 
  6. your program's current version number.
  7.  
  8. Copyright Joseph Laffey, 1993. You may use this code snippet in anything you'd
  9. like. It would be cool if you could give me a little credit... Of course, USE AT
  10. YOUR OWN RISK; I'm not responsible for anything, etc., etc. joelaff@aol.com
  11.  
  12. HISTORY: 
  13. 11/93 dgp downloaded VersStr.c from Compuserve
  14. 12/19/93 dgp Removed excess whitespace. Renamed function from GetVersStr to 
  15.             GetVersionString. Now allocate and return string instead of copying 
  16.             to user-allocated string argument. Added error checking.
  17. */
  18. #include "VideoToolbox.h"
  19. //#include <Resources.h>
  20. //#include <Memory.h>
  21. #define    VERS_RES_ID        1    /* resource ID of 'vers' to use (usually 1 as of Sys7.1)*/
  22. #define    BYTE_OFFSET        6    /* the offset of the pascal-style version string */
  23.                             /* from the beginning of the 'vers' resource. */
  24.                             /*  Apple MAY change this-- hopefully not!!! */
  25. char *GetVersionString(void);
  26.  
  27. char *GetVersionString(void)
  28. {
  29.     Handle vers;
  30.     unsigned char *s1;
  31.     char *s2;
  32.     
  33.     vers=Get1Resource('vers',VERS_RES_ID);
  34.     if(vers==NULL)return "";
  35.     HLock(vers);
  36.     s1=(unsigned char *)(*vers + BYTE_OFFSET);
  37.     if(BYTE_OFFSET+*s1+1>SizeResource(vers))
  38.         PrintfExit("GetVersionString: Illegal 'vers' resource.\n");
  39.     s2=NewPtr(*s1+1);
  40.     if(s2==NULL)PrintfExit("GetVersionString: couldn't allocate string.\n");
  41.     p2cstr(s1);
  42.     strcpy(s2,(char *)s1);
  43.     ReleaseResource(vers);
  44.     return s2;
  45. }